<template>
  <div class="header_content">
    <!-- 顶部内容 -->
    <div class="title">
      <span>后台管理系统</span>
    </div>
    <div class="header_right">
      <!-- 个人信息链接 -->
      <div class="right_content">
        <div>欢迎您，{{ username }}</div>
        <div class="setting" @click="setting">
          <i class="el-icon-s-tools tools"></i><span class="txt">设置</span>
        </div>
        <div>
          <a class="logout" href="javascript:void(0)" @click="logout">注销</a>
        </div>
      </div>
    </div>
  </div>
</template>

<script>
export default {
  name: "HeaderComponents",
  data() {
    return {
      username: JSON.parse(localStorage.getItem("User")).username?JSON.parse(localStorage.getItem("User")).username:'admin',
    };
  },
  methods: {
    //进入设置页面
    setting() {
      //使用this.$router.push或this.$router.replace时，先判断当前路由是否与目标路由相同，如果相同则不执行导航。
      if (this.$route.path !== "/setting") {
        this.$router.push("/setting");
      }
    },
    //注销登录
    logout() {
      localStorage.clear();
      window.location.reload();
    },
  },
};
</script>

<style scoped>
.header_content {
  display: flex;
  justify-content: space-between;
  height: 90px;
}

.title {
  line-height: 90px;
}

.title span {
  margin-left: 50px;
  color: #ffffff;
  font-size: 28px;
  font-weight: 600;
}

.header_right {
  line-height: 90px;
  color: #ffffff;
}

.right_content {
  display: flex;
  font-size: 16px;
}
.right_content > div {
  margin-right: 30px;
}

.right_content i.tools {
  font-size: 16px;
  margin-right: 3px;
}

.logout {
  color: #ffffff;
}

.setting {
  cursor: pointer;
}

.txt {
  font-size: 16px;
}
</style>